﻿using NBlog.Web.Application.Service.Entity;
using NBlog.Web.Application.Service.Internal.Caching;
using NBlog.Web.Application.Storage;

namespace NBlog.Web.Application.Service.Internal
{
    public class ConfigService : IConfigService
    {
        private readonly IRepository _repository;
        private readonly ICachePolicy _cachePolicy;

        public ConfigService(IRepository repository, IDefaultCachePolicy cachePolicy)
        {
            _repository = repository;
            _cachePolicy = cachePolicy;
        }

        public Config Current
        {
            get { return _cachePolicy.Get("ConfigCacheKey", () => _repository.Single<Config>("settings")); }
        }
    }
}